<template>
	<view class="content">
		<!-- <u-navbar title="邻里帮租" :bgColor="bgColor" leftIconSize='0px' placeholder='true' titleStyle='font-weight: bold;'>
		</u-navbar> -->
		<view class="contentUpper">
			<view>
				<image src="@/static/register.png" mode="widthFix"
					style="width: 16vw;display: flex;align-items: center;"></image>
			</view>
			<view style="margin-left: 1vw;">
				<view style="font-weight: bold;font-size: 22px;">
					邻里帮租
				</view>
				<view style="font-size: 13px;margin-top: 3px;">
					优质房源，便捷放心
				</view>
			</view>
			<view style="position: absolute;right: 0;">
				<image src="@/static/selection.png" mode="widthFix" style="width: 40vw;"></image>
			</view>
			<!-- <u-image src="@/static/selection.png" mode="widthFix" width="30vw" :fade="true"></u-image> -->
		</view>
		<view class="contentBelow">
			<view class="title">
				请选择您的需求
			</view>
			<view class="substance" v-for="(item,index) in repeat" :key="index" @click="enter(item.title)">
				<view class="">
					<image :src="item.icon" mode="widthFix" style="width: 40px;" />
				</view>
				<view style="margin-left: 9px;font-weight: bold;font-size: 14px;">
					{{item.title}}
				</view>
				<view style="margin-left: auto;">
					<image src="@/static/rent5.png" mode="widthFix" style="width: 8vw;" />
				</view>
			</view>
		</view>
	</view>
</template>
<script setup>
	import {
		get,
		post
	} from '@/serve/method.js';
	import {
		reactive,
		ref
	} from 'vue';
	import {
		onLoad
	} from '@dcloudio/uni-app'
	const openid = ref()
	onLoad((query) => {
		console.log(query, 777777777777777)
		openid.value = decodeURIComponent(query.scene)
		console.log(openid.value, 'openid的获取')
		wx.login({
			success(res) {
				if (res.code) {
					let urls = "/api/minLogin"
					get(urls, {
						code: res.code
					}).then((res) => {
						console.log(res, 88888)
						let three = {
							"vuex_token": res.data.jwtToken,
							"vuex_user": res.data
						}
						uni.setStorage({
							key: 'lifeData',
							data: three,
							success: function(resdl) {
								console.log(resdl, '储存');
								if (openid.value == 'undefined') {
									openid.value = ''
									console.log('自己进来的')
								} else {
									let urlstwo = `/api/qrcode/editOne/${openid.value}`
									get(urlstwo).then((restwo) => {
										console.log(restwo, '二维码绑定判断1')
										console.log(restwo.data, '二维码绑定判断2')
										if (restwo.data.userId !== null) {
											openid.value = restwo.data.userId
										} else {
											console.log(openid.value,
												'二维码绑定判断3')
											console.log(res.data.userId,
												'二维码绑定判断4')
											uni.showModal({
												title: '提示',
												content: '是否绑定该二维码',
												success: function(
													resfilse
												) {
													if (resfilse
														.confirm
													) {
														let urlsthree =
															`/api/qrcode/editSave?id=${openid.value}&userId=${res.data.userId}`
														post(
																urlsthree
															)
															.then((
																resthree
															) => {
																console
																	.log(
																		resthree,
																		'二维码绑定判断5'
																	)
																uni.showModal({
																	title: '提示',
																	content: '二维码绑定成功',
																	showCancel: false,
																	success: function(
																		resfour
																	) {
																		if (resfour
																			.confirm
																		) {
																			openid
																				.value =
																				res
																				.data
																				.userId
																			console
																				.log(
																					openid
																					.value,
																					'二维码绑定判断6'
																				);
																		}
																	}
																});
															})
													}
												}
											});

										}
									})
								}
							}
						});
					})
				} else {
					console.log('登录失败！' + res.errMsg)
				}
			}
		})
	})
	const repeat = reactive([{
			icon: '/static/rent1.png',
			title: '我要出租/转租',
		}, {
			icon: '/static/rent2.png',
			title: '我要租房',
		},
		// {
		// 	icon: '/static/rent3.png',
		// 	title: '公证签约(0元享)',
		// }, {
		// 	icon: '/static/rent4.png',
		// 	title: '无忧租住',
		// },
	])
	const enter = (item) => {
		let one = null
		if (item == "我要出租/转租") {
			one = 1
		}
		if (item == "我要租房") {
			one = 2
		}
		if (item == "公证签约(0元享)") {
			one = 3
		}
		if (item == '无忧租住') {
			one = 4
		}
		// console.log(one, 222)

		uni.getStorage({
			key: 'lifeData',
			success: function(res) {
				let urls = "/api/user/addModlueIdAndUnionId"
				post(urls, {
					"moduleId": one,
					"userId": res.data.vuex_user.userId
				}).then((res) => {
					console.log(res)
					if (one == 1) {
						uni.reLaunch({
							url: `/pages/detail/addHouse?openid=${openid.value}`
						});
					} else {
						uni.switchTab({
							url: '/pages/homepage/index'
						})
					}

				})
			}
		})
	}
</script>
<style scoped lang="scss">
	.content {
		background-color: #FFDA06;

		.contentUpper {
			height: 10vh;
			display: flex;
			align-items: center;
			padding: 13vh 2vw 0;
			position: relative;
		}

		.contentBelow {
			// border: 100px 0;
			border-radius: 20px 20px 0 0;
			// height: 75vh;
			background-color: #ffffff;
			padding: 0 4vw;

			.title {
				padding-top: 25px;
				font-weight: bold;
				margin-bottom: 25px;
				font-size: 15px;
			}

			.substance {
				display: flex;
				align-items: center;
				background-color: #F4F4F4;
				margin-top: 10px;
				margin-bottom: 20px;
				padding: 10px 8px;
				border-radius: 10px;
			}
		}
	}
</style>